<?php
// +--------------------------------------------------------------------------
// | ISDCE [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2017 载攸道 版权所有 <TEL:086-010-57209502>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * [ CMS ]
 */
namespace CMS\Controller;
use Common\Controller\AdminController;

/**
 * 系统设置
 */
class ConfController extends AdminController{
	
	/**
	 * 配置管理
	 */
    public function Manage(){
		
		
		
		//页面配置
		$page = array(
			
			'title'=>'系统设置',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		
		);
		
		$this->assign('page',$page);
		
		$m_cms_content = M('cms_content');
		
		$map['type'] = get_cms_model_conf('CMS_CONF');
		$map['status'] = 1;
		
		$list = $m_cms_content->where($map)->select();
		
		$this->assign('list',$list);

		$this->display();
	}
	
	/**
	 * 新增配置
	 */
	public function Create(){
		

		//判断是否是ajax请求
		if(IS_AJAX){

			$m_cms_content = M('cms_content');
			
			
			//获得数据
			$data = I();
			
			$data['value'] = I('param.value','','');
			$data['uid'] = getUID();
			$data['type'] = get_cms_model_conf('CMS_CONF');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = 1;
			
			$result = $m_cms_content->add($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
			
			
				
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 编辑配置
	 */
	public function Edit(){
    

		//判断是否是ajax请求
		if(IS_AJAX){

			$m_cms_content = M('cms_content');
		
			$map['id'] = I('param.id');
			
			set_cms_draft($map['id']); //保存草稿
			
			$data = I('');
			unset($data['id']);
			$data['uid'] = getUID();
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			
			$result = $m_cms_content->where($map)->save($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 批量删除配置
	 */
	public function Delete($id,$status=0){

		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_cms_content = M('cms_content');
		
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				
			
				$id = explode(',',$id); 
				
				
				foreach($id as $i=>$k){
					
					$map['id'] = $id[$i];
					$data['status'] = $status;
					
					$m_cms_content->where($map)->save($data);
				
					
				}
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
			
	
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);


	}
	
	
}